package cn.iocoder.yudao.module.wine.controller.app.uservisitor;

import cn.iocoder.yudao.module.wine.controller.app.userfans.vo.AppUserFansReqVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.wine.controller.app.uservisitor.vo.*;
import cn.iocoder.yudao.module.wine.dal.dataobject.uservisitor.UserVisitorDO;
import cn.iocoder.yudao.module.wine.service.uservisitor.UserVisitorService;

@Tag(name = "用户 APP - 访客信息")
@RestController
@RequestMapping("/wine/user-visitor")
@Validated
public class AppUserVisitorController {

    @Resource
    private UserVisitorService userVisitorService;

    @PostMapping("/create")
    @Operation(summary = "添加访客信息")
    public CommonResult<Long> createUserVisitor(@Valid @RequestBody AppUserVisitorSaveReqVO createReqVO) {
        return success(userVisitorService.createUserVisitor(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新访客信息")
    public CommonResult<Boolean> updateUserVisitor(@Valid @RequestBody AppUserVisitorSaveReqVO updateReqVO) {
        userVisitorService.updateUserVisitor(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除访客信息")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteUserVisitor(@RequestParam("id") Long id) {
        userVisitorService.deleteUserVisitor(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得访客信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppUserVisitorRespVO> getUserVisitor(@RequestParam("id") Long id) {
        UserVisitorDO userVisitor = userVisitorService.getUserVisitor(id);
        return success(BeanUtils.toBean(userVisitor, AppUserVisitorRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得访客信息分页")
    public CommonResult<PageResult<AppUserVisitorRespVO>> getUserVisitorPage(@Valid AppUserVisitorPageReqVO pageReqVO) {
        PageResult<UserVisitorDO> pageResult = userVisitorService.getUserVisitorPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, AppUserVisitorRespVO.class));
    }


    @GetMapping("/list")
    @Operation(summary = "获取访客信息列表")
    public CommonResult<List<AppUserVisitorListRespVO>> getUserVisitorList(@Valid AppUserFansReqVO reqVO) {
        List<AppUserVisitorListRespVO> list = userVisitorService.getUserVisitorList(reqVO);
        return success(list);
    }

//    @GetMapping("/export-excel")
//    @Operation(summary = "导出访客信息 Excel")
//    @OperateLog(type = EXPORT)
//    public void exportUserVisitorExcel(@Valid AppUserVisitorPageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<UserVisitorDO> list = userVisitorService.getUserVisitorPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "访客信息.xls", "数据", UserVisitorRespVO.class,
//                        BeanUtils.toBean(list, UserVisitorRespVO.class));
//    }

}
